package com.clothing.entity;

import com.clothing.CommonAttributes;
import com.clothing.utils.Utils;

import javax.persistence.*;
import java.util.Date;

/**
 * @ClassName: User
 * @Description: TODO(Entity-User)
 * @author Charles.Tao
 * @date 2017年8月21日 下午4:04:14
 * @version 1.0
 */
@Entity
@Table(name = "user", uniqueConstraints = @UniqueConstraint(columnNames = "openid"))
public class User extends BaseEntity
{
    /**
     * @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
     */
    private static final long serialVersionUID = -5862204957526495998L;

    public static final String PRINCIPAL_ATTRIBUTE_NAME = User.class.getName() + ".PRINCIPAL";

    public static final String SESSION_CACHE_NAME = "thirdSession";

    /**
     * @ClassName: Type
     * @Description: TODO(用户类型)
     * @author Charles
     * @date 2018年5月25日 上午11:13:00
     * @version 1.0
     */
    public enum Type
    {
        /*用户 */
        user,
        /*商家*/
        business
    }

    /**
     * @ClassName: Status
     * @Description: TODO(状态)
     * @author Charles
     * @date 2018年5月25日 上午11:14:38
     * @version 1.0
     */
    public enum Status
    {
        /*未申请*/
        unApply,

        /*待审核 */
        unChecked,

        /*已通过 */
        pass,

        /*不通过 */
        notPass
    }

    private String openid;

    private Type type;

    private Status status;

    private String nickname;

    private String unionid;

    private String brief;

    private String headImgUrl;

    private String lastLoginIp;

    private Date lastLoginDate;

    private Integer sex;

    private String mobile;

    private String address;

    private String weChat;

    private Boolean messageNotice;

    public String getBrief()
    {
        return this.brief;
    }

    public void setBrief(String brief)
    {
        this.brief = brief;
    }

    @Column(name = "head_img_url")
    public String getHeadImgUrl()
    {
        return this.headImgUrl;
    }

    public void setHeadImgUrl(String headImgUrl)
    {
        if (!Utils.isEmpty(headImgUrl))
        {
            if (headImgUrl.startsWith(CommonAttributes.SITE_URL))
            {
                headImgUrl = headImgUrl.substring(CommonAttributes.SITE_URL.length(), headImgUrl.length());
            }
        }
        this.headImgUrl = headImgUrl;
    }

    @Column(name = "last_login_ip")
    public String getLastLoginIp()
    {
        return this.lastLoginIp;
    }

    public void setLastLoginIp(String lastLoginIp)
    {
        this.lastLoginIp = lastLoginIp;
    }

    @Column(name = "sex", nullable = false)
    public Integer getSex()
    {
        return sex;
    }

    public void setSex(Integer sex)
    {
        this.sex = sex;
    }

    @Column(name = "mobile", nullable = false)
    public String getMobile()
    {
        return mobile;
    }

    public void setMobile(String mobile)
    {
        this.mobile = mobile;
    }

    @Column(name = "last_login_date")
    public Date getLastLoginDate()
    {
        return lastLoginDate;
    }

    public void setLastLoginDate(Date lastLoginDate)
    {
        this.lastLoginDate = lastLoginDate;
    }

    @Column(name = "openid", unique = true, nullable = false)
    public String getOpenid()
    {
        return openid;
    }

    public void setOpenid(String openid)
    {
        this.openid = openid;
    }

    @Column(name = "nickname", nullable = false)
    public String getNickname()
    {
        return nickname;
    }

    public void setNickname(String nickname)
    {
        this.nickname = nickname;
    }

    @Column(name = "unionid")
    public String getUnionid()
    {
        return unionid;
    }

    public void setUnionid(String unionid)
    {
        this.unionid = unionid;
    }

	@Column(name="address")
    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    @Column(name = "type", nullable = false)
    public Type getType()
    {
        return type;
    }

    public void setType(Type type)
    {
        this.type = type;
    }

    @Column(name = "status", nullable = false)
    public Status getStatus()
    {
        return status;
    }

    public void setStatus(Status status)
    {
        this.status = status;
    }

    /*微信账号*/
    @Column(name = "we_chat")
    public String getWeChat() {
        return weChat;
    }

    public void setWeChat(String weChat) {
        if (!Utils.isEmpty(weChat))
        {
            if (weChat.startsWith(CommonAttributes.SITE_URL))
            {
                weChat = weChat.substring(CommonAttributes.SITE_URL.length(), weChat.length());
            }
        }
        this.weChat = weChat;
    }

    /**
     * 完整微信图片地址
     *
     * @return
     */
    @Transient
    public String getFullWeChat() {
        if (Utils.isEmpty(weChat)) {
            return null;
        }
        return CommonAttributes.SITE_URL + weChat;
    }

    @Column(name = "message_notice", nullable = false)
    public Boolean getMessageNotice() {
        return messageNotice;
    }

    public void setMessageNotice(Boolean messageNotice) {
        this.messageNotice = messageNotice;
    }

    /**
     * 初始化
     */
    @PrePersist
    public void prePersist()
    {
        setType(Type.user);
        setStatus(Status.unChecked);
        setMessageNotice(Boolean.FALSE);
    }
}
